<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.apache.commons.dbcp.BasicDataSource" %>
<%-- 
尤其是循环标签，在jsp最终输出的html中会产生大量的空行，使得性能降低。
方法一：（所有的jsp页面）在web.xml 中添加以下设置
<jsp-config>
	<jsp-property-group>
		<url-pattern>*.jsp</url-pattern>
		<trim-directive-whitespaces>true</trim-directive-whitespaces>
	</jsp-property-group>
</jsp-config> 
方法二：单个JSP
<%@ page trimDirectiveWhitespaces="true"%>

方法三：针对servlet
tomcat 目录下 \conf\web.xml文件，在servlet增加参数
<init-param>
<param-name>trimSpaces</param-name>
<param-value>true</param-value>
</init-param>

 --%>
<%@ page trimDirectiveWhitespaces="true"%>

<%
	//直接使用DataSource
	ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(pageContext.getServletContext());
	BasicDataSource ds =(BasicDataSource) context.getBean("dataSource");
	out.write(ds.getUsername());
	
	//直接使用sessionFactory
	//org.springframework.orm.hibernate3.LocalSessionFactoryBean sf =(org.springframework.orm.hibernate3.LocalSessionFactoryBean) context.getBean("sessionFactory");
	
	//直接使用hibernateTemplate
	org.springframework.orm.hibernate3.HibernateTemplate ht =(org.springframework.orm.hibernate3.HibernateTemplate) context.getBean("hibernateTemplate");
	out.write(ht.getClass().toString());
	ht.executeFind(new org.springframework.orm.hibernate3.HibernateCallback() {
			public Object doInHibernate(org.hibernate.Session s) throws org.hibernate.HibernateException,
					java.sql.SQLException {
				org.hibernate.Query query = s.createSQLQuery("select node_name from purejsp");
				java.util.List list = query.list();
				return list;
			}
		});
 %>
